﻿using System;
using GeneralDFS.DataEntity.Enum;

namespace GeneralDFS.BusinessLogical.NodeOperate
{
    public class JudgeNodeOperate
    {
        public static INodeOperate GetNodeOperate(String command)
        {
            if (String.IsNullOrEmpty(command))
            {
                return null;
            }

           String[] arr=command.Trim().Split(' ');

           INodeOperate operate = null;

           if (arr.Length >= 1)
           {
               switch (arr[0])
               {
                       /*
                   case CommandType.UploadBlocks:operate=new UploadBlocks();
                       break;
                        * */
                   case CommandType.DeleteBlock: operate = new DeleteBlock();
                       break;
                   case CommandType.SendBlockToDataNode:operate = new SendBlock();
                       break;
                   default:operate=new DefaultOperate();
                       break;
               }              
           }
           if (arr.Length >= 2)
           {
               var newParam=new String[arr.Length-1];
               Array.Copy(arr, 1, newParam, 0, newParam.Length);
               if (operate != null) operate.ProcessParam(newParam);
           }

           return operate;
        }
    }
}
